<template>
	<view>
		<view class="header status_bar">
			<view class="back iconfont" @tap="backPage">&#xe779;</view>
			<view class="text">选择品牌</view>
		</view>
		<view class="clear_box"></view>
		
		<city-select
			@cityClick="cityChose"
			:formatName="formatName"
			:activeCity="activeCity"
			:hotCity="hotCity"
			:obtainCitys="obtainCitys"
			:isSearch="true"
			ref="citys"
		></city-select>
	</view>
</template>

<script>
import citys from './citys.js';
// console.log(citys.length)
import citySelect from '@/components/brand/city-select.vue'
export default {
	data() {
		return {
			//需要构建索引参数的名称（注意：传递的对象里面必须要有这个名称的参数）
			formatName: 'name',
			//当前城市
			activeCity: {},
			//热门城市
			hotCity: [],
			//显示的城市数据
			obtainCitys: [],
			type:0,
		}
	},
	components: {
		citySelect
	},
	onLoad(e) {
		//动态更新数据
		uni.showLoading({
			title:'加载中...',
			mask: true
		})
		setTimeout(() => {
			//修改数据格式
			this.formatName = 'name'
			//修改当前城市
			// this.activeCity = {
			// 	cityName: '南京',
			// 	cityCode: 110100
			// }
			//修改热门城市
			this.hotCity = [
				// {
				// 	cityName: '南京',
				// 	cityCode: 110100
				// },
				// {
				// 	cityName: '北京',
				// 	cityCode: 110102
				// }
			]
			//修改构建索引数据
			uni.hideLoading();
				//this.obtainCitys = citys;
			// this.obtainCitys = this.vuex.appInfo.brands;
			// uni.showToast({
			// 	icon: 'none',
			// 	title: '更新数据成功',
			// 	// #ifdef MP-WEIXIN
			// 	duration: 2000,
			// 	// #endif
			// 	mask: true
			// })
		}, 200),
		this.loadData();
		if (e.type){
			this.type = e.type;
		}
	},
	methods: {
		backPage() {
			uni.navigateBack({});
		},
		gotopage(e) {
			let url = e.currentTarget.dataset.url;
			this.$r(url);
		},
		loadData(){
			let that = this;
			that.Net._get('index/app_init_data', {}, res => {
				if (res.code == 1) {
					that.obtainCitys = res.data.appInfo.brands;
					that.hotCity = res.data.appInfo.hot_brands;
				}
			});
		},
		cityClick(item) {
			uni.$emit('pu_brand',item)
			setTimeout(()=>{
				uni.navigateBack({});
			},300)
		},
		
		cityChose(item){
			uni.$emit('pu_brand',item)
			setTimeout(()=>{
				uni.navigateBack({});
			},300)
		}
	}
}
</script>

<style></style>
